package com.jushu.storbox.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jushu.storbox.R;
import com.jushu.storbox.callback.OnViewClickListener;
import com.jushu.storbox.entities.SharedUser;

public class ActionShowSharedFriendsAdapter extends AbsTemplateAdapter<SharedUser> {
	private List<SharedUser> adUserList;
	private Context context;
	private ViewHolder viewHolder;
	OnViewClickListener<SharedUser> clickListener = null;

	@SuppressWarnings("unchecked")
	public ActionShowSharedFriendsAdapter(Context context, int resource, List<SharedUser> objects) {
		super(objects);
		this.adUserList = objects;
		this.context = context;
		clickListener = (OnViewClickListener<SharedUser>) context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(R.layout.action_shared_friends_info_item, null);
			viewHolder = new ViewHolder();
			viewHolder.department = (TextView) convertView.findViewById(R.id.simple_department);
			viewHolder.name = (TextView) convertView.findViewById(R.id.simple_name);
			viewHolder.deleteNumber = convertView.findViewById(R.id.shared_friends_delete);
			convertView.setTag(viewHolder);
		}
		viewHolder = (ViewHolder) convertView.getTag();
		final SharedUser sharedUser = adUserList.get(position);
		viewHolder.name.setText(sharedUser.getSharedUserName());
		viewHolder.department.setText(sharedUser.getSharedDepartment());
		viewHolder.deleteNumber.setOnClickListener(new OnClickListener() {
			public void onClick(View view) {
				if (clickListener != null) {
					clickListener.onViewClick(view, sharedUser);
				}
			}
		});
		return convertView;
	}

	public static class ViewHolder {
		public TextView name, jobNumber, department;
		public View deleteNumber;
	}
}
